/*Author Rajith Chathunga,
 *		 Computer Science and Engineering,
 *		 University of Moratuwa.
 *
 * Class name : TravelNews
 * 
 *  			
 * This class store travel news categories and their rss URLs. And also send them to the QNews class.
 *  This class extends Activity and implements onClickListener.*/

package chathunga.qNews;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;

public class TravelNews extends Activity implements OnClickListener {
	ListView lv;
	String ss,sss;
	Bundle b = new Bundle();
	NewsObjects no;
	TextView optn;
	ImageView img;
	private ArrayList<Object> ar=new ArrayList<Object>();	

	public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.travelnews); 
        optn=(TextView)findViewById(R.id.addn);
        img=(ImageView)findViewById(R.id.qn);
        img.setOnClickListener(this);
        optn.setOnClickListener(this);
        data();  
        
        lv=(ListView)findViewById(R.id.sportlist);
        lv.setAdapter(new ArrayAdapter<Object>(this,R.layout.list_black_text,R.id.list_content , ar));
        lv.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
        long arg3) {
        	Toast.makeText(getBaseContext(), ""+ar.get(arg2), Toast.LENGTH_LONG).show();
        	
        ss=ar.get(arg2).toString();
        no=(NewsObjects) ar.get(arg2);
        sss=no.toStr();
        	operation();

	}
        });
	
        
        
	

}
	//This method contains travel news categories and rss URLs in an ArrayList
	public void data(){
		
		ar.add(new NewsObjects("Travel News","http://rssfeeds.usatoday.com/UsatodaycomTravel-TopStories"));
        ar.add(new NewsObjects("Today in the Sky","http://rssfeeds.usatoday.com/TP-TodayInTheSky"));
        ar.add(new NewsObjects("Travel Hotels News","http://rssfeeds.usatoday.com/UsatodayTravel-Hotels"));
        ar.add(new NewsObjects("Business Travel","http://rssfeeds.usatoday.com/UsatodaycomTravel-BT-Grossman"));
        ar.add(new NewsObjects("Travel Flights News","http://rssfeeds.usatoday.com/UsatodayTravel-Flights"));
        ar.add(new NewsObjects("Travel Destinations News","http://rssfeeds.usatoday.com/UsatodayTravel-Destinations"));
	
	}
	//This method is called when click on a news category.
	public void operation(){
		
		if(ss=="Travel News"){
		Intent it= new Intent(this,QNews.class);
		b.putString("key", sss);
		it.putExtras(b);
		startActivity(it);
		
		}
		if(ss=="Today in the Sky"){
			
			Intent it= new Intent(this,QNews.class);
			b.putString("key", sss);
			it.putExtras(b);
			startActivity(it);
			
			}
		
		if(ss=="Travel Hotels News"){
			
			Intent it= new Intent(this,QNews.class);
			b.putString("key", sss);
			it.putExtras(b);
			startActivity(it);
			
			}
		
		if(ss=="Business Travel"){
			
			Intent it= new Intent(this,QNews.class);
			b.putString("key", sss);			
			it.putExtras(b);
			startActivity(it);
			
			}
		
		if(ss=="Travel Flights News"){
			
			Intent it= new Intent(this,QNews.class);
			b.putString("key", sss);
			it.putExtras(b);
			startActivity(it);
			
			}
		
		if(ss=="Travel Destinations News"){
			
			Intent it= new Intent(this,QNews.class);
			b.putString("key", sss);
			it.putExtras(b);
			startActivity(it);
			
			}
		
	}
	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		if(v.getId()==R.id.addn){
			
			Intent it= new Intent(this,Option.class);
			startActivity(it);
			
		}
		
		if(v.getId()==R.id.qn){
			
			this.finish();
			Intent bToHome= new Intent(this,MainQNews.class);
			startActivity(bToHome);
			finish();
			
		}
	}

}
